﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace BDSim
{
    class SubGroundSegmentDataProvider : BDSimDataProvider
    {
        private SubGroundSegment _Parent;

        /// <summary>
        /// 该数据模型的父级
        /// </summary>
        public SubGroundSegment Parent
        {
            get { return _Parent; }
            set { _Parent = value; }
        }

        #region 命令定义

        /// <summary>
        /// 主控站
        /// </summary>
        MenuCommand AddMasterStationCmd = new MenuCommand();

        /// <summary>
        /// 注入站
        /// </summary>
        MenuCommand AddInjectionStationCmd = new MenuCommand();

        /// <summary>
        /// 监测站
        /// </summary>
        MenuCommand AddMonitorStationCmd = new MenuCommand();


       /// <summary>
       /// 清空按钮
       /// </summary>
       MenuCommand DeleteCmd = new MenuCommand();

        #endregion

        #region 命令集合初始化

        public override void DefineCommand()
        {
            AddMasterStationCmd.Header = "主控站";
            AddMasterStationCmd.DefineExcuteCommand(AddMasterStationFun_Execute, AddMasterStationFun_CanExecute);
            MenuCommandList.Add(AddMasterStationCmd);

            AddInjectionStationCmd.Header = "注入站";
            AddInjectionStationCmd.DefineExcuteCommand(AddInjectionStationFun_Execute, AddInjectionStationFun_CanExecute);
            MenuCommandList.Add(AddInjectionStationCmd);

            AddMonitorStationCmd.Header = "监测站";
            AddMonitorStationCmd.DefineExcuteCommand(AddMonitorStationFun_Execute, AddMonitorStationFun_CanExecute);
            MenuCommandList.Add(AddMonitorStationCmd);

            DeleteCmd.Header = "删除";
            DeleteCmd. DefineExcuteCommand(DeleteFun);
            MenuCommandList.Add(DeleteCmd); 

        }

        #endregion

        #region 命令执行内容

        void AddMasterStationFun_Execute(object param)
        {
            StationCollection StationCollection_Master = new StationCollection();
            StationCollection_Master.Parent = Parent;
            StationCollection_Master.Type = EStationType.MasterStation;
            StationCollection_Master.Name = "主控站";
            _Parent.GroundList.Add(StationCollection_Master);
        }

        bool AddMasterStationFun_CanExecute(object param)
        {
            bool flag = false;
            if (BDSimObject.GlobalStatus == ESimStatus.UnInited || BDSimObject.GlobalStatus == ESimStatus.End)
            {
                flag = true;
                foreach (var stationlist in Parent.GroundList)
                {
                    if (stationlist.Type == EStationType.MasterStation)
                    {
                        flag = false;
                        break;
                    }
                }
            }
            return flag;
        }

        void AddInjectionStationFun_Execute(object param)
        {
            StationCollection StationCollection_Injection = new StationCollection();
            StationCollection_Injection.Parent = Parent;
            StationCollection_Injection.Type = EStationType.InjectionStation;
            StationCollection_Injection.Name = "注入站";
            _Parent.GroundList.Add(StationCollection_Injection);
        }

        bool AddInjectionStationFun_CanExecute(object param)
        {
            bool flag = false;
            if (BDSimObject.GlobalStatus == ESimStatus.UnInited || BDSimObject.GlobalStatus == ESimStatus.End)
            {
                flag = true;
                foreach (var stationlist in Parent.GroundList)
                {
                    if (stationlist.Type == EStationType.InjectionStation)
                    {
                        flag = false;
                        break;
                    }
                }
            }
            return flag;
        }

        void AddMonitorStationFun_Execute(object param)
        {
            StationCollection StationCollection_Monitor = new StationCollection();
            StationCollection_Monitor.Parent = Parent;
            StationCollection_Monitor.Type = EStationType.MonitorStation;
            StationCollection_Monitor.Name = "监测站";
            _Parent.GroundList.Add(StationCollection_Monitor);
        }

        bool AddMonitorStationFun_CanExecute(object param)
        {
            bool flag = false;
            if (BDSimObject.GlobalStatus == ESimStatus.UnInited || BDSimObject.GlobalStatus == ESimStatus.End)
            {
                flag = true;
                foreach (var stationlist in Parent.GroundList)
                {
                    if (stationlist.Type == EStationType.MonitorStation)
                    {
                        flag = false;
                        break;
                    }
                }
            }
            return flag;
        }

        void DeleteFun(object param)
        {
            Parent.Parent.SubGroundSegmentList.Remove(Parent);
        }
        #endregion
    }
}
